#include "File.h"
#include <header.h>




// 构造函数
File* createFile(int fileid, const char* filename, int filesize, const char* filemd5, int fileparent, const char* filepath) {
    // 分配内存
    File* newFile = (File*)malloc(sizeof(File));
    if (newFile == NULL) {
        perror("Failed to allocate memory");
        return NULL;
    }

    // 初始化成员
    newFile->fileid = fileid;
    strncpy(newFile->filename, filename, sizeof(newFile->filename) - 1);
    newFile->filename[sizeof(newFile->filename) - 1] = '\0';  // 确保以 null 结尾
    newFile->filesize = filesize;
    strncpy(newFile->filemd5, filemd5, sizeof(newFile->filemd5) - 1);
    newFile->filemd5[sizeof(newFile->filemd5) - 1] = '\0';  // 确保以 null 结尾
    newFile->fileparent = fileparent;
    strncpy(newFile->filepath, filepath, sizeof(newFile->filepath) - 1);
    newFile->filepath[sizeof(newFile->filepath) - 1] = '\0';  // 确保以 null 结尾

    return newFile;
}